require(['../config'], () => {
    require(['request', 'template','header','bootstrap','footer','zpages'], (request, template,header) => {
      class List{
        constructor () {
          this.list=[]
          this.initList=[]
          this.init()
          this.sort()
         
        }
        init(){
          let id=location.search.slice(4)
          const word=location.search.slice(8)
          if(location.search.includes('id') && id<999){
            request.getShopList(id).then(value=>{
              this.list=value.data.items.list
              const list=this.list
              this.initList=JSON.parse(JSON.stringify(list))
              const data=value.data
              $('#list_shopList_warp').html( template('list_shopList',{list,data}))
              this.addTocart()
            })
          }else if(location.search.includes('id') && id>999){
            request.getBannerAcitve(id).then(value=>{
              this.list=value.data.list
              const list=this.list
              this.initList=JSON.parse(JSON.stringify(list))
              const data=value.data
              $('#list_shopList_warp').html( template('list_shopList',{list,data}))
              this.addTocart()
            })
          }
          
          if(location.search.includes('search')){
            request.getSearchList(word).then(value=>{
              this.list=value.data.list
              const list=this.list
              this.initList=JSON.parse(JSON.stringify(list))
              const data=value.data
              $('#list_shopList_warp').html( template('list_shopList',{list,data}))
              this.addTocart()
            })
          }

         
        }

        addTocart(){
         header.addTocart($('#list_shopList_warp'),this.initList)
        }
        
        sortMethod(data,type){
          let result=[]
          if(type===1){
            result=this.initList
          }else if(type===2){
            result=data.sort((a,b)=>{
              return a.price-b.price
            })
          }else if(type===3){
            result=data.sort((a,b)=>{
              return b.price-a.price
            })
          }
          return result
        }

        sort(){
          const _this=this
          $('.list>.sort>span').on('click',function(){
              let list=_this.list
              const type=$(this).data('type')
              list = _this.sortMethod(list,type)
              const data=''
              $('#list_shopList_warp').html( template('list_shopList',{list,data}))
          })
        }
      }
      new List()
    })
  })

  function searchValue(data){
    const $searchTitle=$('#title')
    data=data.s
			let fragment=document.createDocumentFragment()
			data.forEach(val=>{
				let li=document.createElement("li")
				li.innerText=val
				fragment.appendChild(li)
				$searchTitle.html("")
			})
			$searchTitle.append(fragment)
  }